<?php
/*
 * Plugin Name: Wap-WordPress
 * Plugin URI: http://www.czxqlove.com/wap-wordpress
 * Description: wap plugin for wordpress.
 * Version: 1.0.1
 * Author: SILENCE
 * Author URI: http://www.czxqlove.com
 */


require_once('func/func_cls.php');

$ww	=	new wapWordPress();

add_action('activate_wap-wordpress/wap-wordpress.php', array(&$ww, 'init'));
add_action('deactivate_wap-wordpress/wap-wordpress.php', array(&$ww, 'uninit'));


function add_ww_options_page() {
	if (function_exists('add_options_page')) { 
		add_options_page('Wap-WordPress', 'Wap-WordPress 配置', 8, basename(__FILE__), 'ww_options_mainpage'); 
	}
} 
add_action('admin_menu', 'add_ww_options_page');

?>
<?php
function ww_options_mainpage(){
	global $ww;
	$filename = $_GET['page'];
	$filen=str_replace('\\\\','\\',$_GET['page']);
	/* 更新选项 */
	if (isset($_POST['info_update'])) {
		$ww->updateAdminOptions($_POST);
	?>
		<div id="message" class="updated fade"><p><strong><?php echo "设置已更新！~~"; ?></strong></p></div>
	<?php
	}
	?>
	<?php $ww_options	=	$ww->getAdminOptions(); ?>

	<div class="wrap" id="ww_content">

	<h2>Wap-WordPress 配置</h2>

		<form method="post" action="<?php echo $_SERVER['PHP_SELF'].'?page='.$filen; ?>">
		<fieldset name="option" style="padding:10px;">
		<legend><h3>基本配置：</h3></legend>
		<p>
			<label for="ww_is_on">开启WAP功能：</label>
			<input type="checkbox" name="ww_is_on" <?php if($ww_options['ww_is_on'] == 'on'){echo 'checked';} ?> />
		</p>
		<p>
			<label for="ww_wap_path">设置WAP页面的根目录：</label>
			<input type="text" name="ww_wap_path" value="<?php echo $ww_options['ww_wap_path']; ?>" />
		</p>
		<P>该路径相对于站点根目录，如：/wap</p>
		<p>========================================</p>
		<p>
			<label for="ww_ad_on">开启Adsense功能：</label>
			<input type="checkbox" name="ww_ad_on" <?php if($ww_options['ww_ad_on'] == 'on'){echo 'checked';} ?> />
		</p>
		<p>
			<label for="ww_ad">输入Google Adsense 移动广告代码(PHP)：<i>&lt;默认为测试代码，开启后请输入自己的代码&gt;</i></label>
			<p>
			<textarea name="ww_ad" cols="80" rows="15"><?php
				$adpath	= $ww->getADPath();
				$fid	= fopen($adpath,'r');
				if($fid){
					$str	= fread($fid,filesize($adpath));
					fclose($fid);
				}
				echo trim($str);
			?></textarea>
			</p>
		</p>
		</fieldset>

		<!-- 检验数据 -->
		<?php wp_nonce_field('update-options') ?>
		<input type="hidden" name="page_options" value="ww" />
		<!-- 提交数据 -->
		<p class="submit">
			<input type="hidden" name="action" value="update" />
			<input type="submit" name="info_update" value="<?php _e('Update Options &raquo;') ?>" />
		</p>
	</form>
	</div>
<?php
}
?>